package db

import (
	"gin-base/base/config"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
)

var dsn string

func init() {
	if config.Ini.String("app.mode") == "prod" {
		dsn = config.Ini.String("mysql.dsn")
	} else {
		dsn = config.Ini.String("mysql.dsn_dev")
	}
}

func Open() *gorm.DB {
	connect, err := gorm.Open("mysql", dsn)
	if err != nil {
		println(err.Error())
		return nil
	}

	return connect
}
